package cn.iune.apptest;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.justep.baas.Utils;

import cn.iune.backcenter.authen.ISaOppersonService;
import cn.iune.backcenter.authen.SaOpperson;

@Controller
public class TestController {
	
	@Autowired
	private IServiceComponentTest serviceComponentTest;
	@Autowired
	private ISaOppersonService personService;
	
	@RequestMapping("/test1")
	@ResponseBody
	public String test1() {
		serviceComponentTest.insertTest();
		return "test1";
	}
	
	@RequestMapping("/test2")
	@ResponseBody
	public String test2(@RequestParam String id) {
//		serviceComponentTest.insertTest();
		serviceComponentTest.insertTest2(id);
		return "test2";
	}

	@RequestMapping("/test")
	public String test() {
		return "test";
	}
	
	@RequestMapping("/getAll")
	@ResponseBody
	public List<SaOpperson> getAll() {
		return serviceComponentTest.getAll();
	}

	
//	@RequestMapping(value="/person/list",method=RequestMethod.GET)
//	public ModelAndView personList(){
//		ModelAndView mav = new ModelAndView("/backcenter/person/list");
//		return mav;
//	}
//
//	@RequestMapping(value="/person/single",method=RequestMethod.GET)
//	public ModelAndView personSingle(){
//		ModelAndView mav = new ModelAndView("/backcenter/person/single");
//		return mav;
//	}
	
	@RequestMapping(value={"/person/list/create"},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject personCreate(@RequestBody JSONObject data, HttpServletRequest request) {
		JSONObject param = data.getJSONObject("param");
		JSONObject json = personService.newData(param);
		
//		Map<String,String> loginfo = SecurityService.getCurrentLoginfo();
//		json.getJSONObject("data").put("loginfo", loginfo);
		
		JSONObject person = (JSONObject) request.getAttribute("person");
		json.getJSONObject("data").put("person", person);
		return json;
	}

	@RequestMapping(value="/person/list/query",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject personQuery(@RequestBody JSONObject data) {
		return personService.queryData(data);
	}

	@RequestMapping(value="/person/list/save",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject personSave(@RequestBody JSONObject object) {
		return personService.saveData(object);
	}

	@RequestMapping(value="/person/list/delete",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject personDelete(@RequestBody JSONObject data) {
		return personService.deleteData(data);
	}

	@RequestMapping(value="/person/queryList",method=RequestMethod.GET)
	@ResponseBody
	public JSONObject personQueryList()  {
//		String enterpriseNo = SecurityService.getCurrentOgn().getsFID();
		JSONObject data = new JSONObject();
		/*
		JSONObject columns = data.getJSONObject("columns"); // 列定义
		String orderBy = data.getString("orderBy"); // 排序
		Integer limit = data.getInteger("limit"); // 分页查询的行数
		Integer offset = data.getInteger("offset"); // 分页查询的行偏移
		String search = data.getString("search"); // 检索关键字
		String filter = data.getString("filter"); // 过滤条件
		String id = data.getString("id");
		*/
		
		JSONObject columns = new JSONObject();
		columns = Utils.entityToDefColJSON(SaOpperson.class);
		data.put("columns", columns);
		data.put("limit", -1);
		data.put("offset", 0);
//		String filter = "SettleInfoOrg.enterpriseNo='"+enterpriseNo+"'";
//		data.put("filter", "SettleInfoOrg.fID='1565161292070'");

		return personService.queryData(data);
	}

	

}
